package com.example.hello.client.WellForm;

import com.example.hello.BootstrapWellForm;
import com.github.gwtbootstrap.client.ui.constants.FormType;
import com.github.gwtbootstrap.client.ui.constants.WellSize;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapWellForm.class)
public class BootstrapWellFormConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapWellForm.class);
    }

    @Override
    public BootstrapWellFormState getState() {
        return (BootstrapWellFormState) super.getState();
    }

    @Override
    public VBootstrapWellForm getWidget() {
        return (VBootstrapWellForm) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapWellFormState state = getState();

        VBootstrapWellForm wellForm = getWidget();

        wellForm.setType(FormType.valueOf(state.getType()));
        wellForm.setSize(WellSize.valueOf(state.getSize()));
    }

}